package cn.wolfcode.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 将默认 content-type 设置为 XML <br/>
 * 
 * 参考: <br/>
 * 
 * http://www.logicbig.com/tutorials/spring-framework/spring-web-mvc/content-negotiation-default-media-type/
 * <br/>
 * 
 * https://stackoverflow.com/questions/33009918/spring-boot-controller-content-negotiation
 */

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.defaultContentType(MediaType.TEXT_XML);
    }


    // 下面解决因在SpringBoot项目中使用 @EnableWebMvc 注解, 而没法使用 swagger-ui 的问题
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * Setup Swagger UI <br/>
         * refer: https://github.com/springfox/springfox/issues/1427
         */
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/",
                "classpath:/META-INF/resources/images");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

    }
}